var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var a in t) t.hasOwnProperty(a) && (e[a] = t[a]);
    })(e, t);
}, function(e, t) {
    function a() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (a.prototype = t.prototype, 
    new a());
}), a = this && this.__decorate || function(e, t, a, n) {
    var i, s = arguments.length, r = s < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, a, n); else for (var o = e.length - 1; 0 <= o; o--) (i = e[o]) && (r = (s < 3 ? i(r) : 3 < s ? i(t, a, r) : i(t, a)) || r);
    return 3 < s && r && Object.defineProperty(t, a, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("PrefabView"), s = e("Global"), c = e("LevelView"), l = e("AudioManager"), d = e("AccountReward"), u = e("GameManager"), p = e("PetManager"), h = e("RecorderManager"), f = e("MyButton"), g = e("GameConfig"), m = e("GameData"), y = e("EquipManager"), v = e("EggsManager"), w = e("ActivityManager"), b = e("DataManager"), P = e("WebManager"), I = e("LoadManager"), G = e("UIManager"), _ = e("AdManager"), A = e("FSVideoAdManager"), k = cc._decorator, M = k.ccclass, C = k.property, D = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.myButton = null, e.recorderBtn = null, e.rankLabel = null, e.rankSprite = null, 
        e.labelSprite = null, e.levelView = null, e.sprite2 = null, e.animation = null, 
        e.star = null, e.light = null, e.rewardView = null, e.model = null, e.count = 0, 
        e.level = 0, e.diamond = 0, e.money = 0, e.piece = 0, e.reward = [], e.isEffect = !1, 
        e.isNext = !1, e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        var e, t;
        w.ActivityManager.getInstance().checkActivity(w.ActivityType.NEWYEAR) ? 5 == m.GD.personIdx ? m.GD.newYearSkinCount < g.GC.newYearSkinCount && (m.GD.newYearSkinCount++, 
        m.GD.newYearSkinCount == g.GC.newYearSkinCount && (m.GD.newYearDrawTotal = 3)) : m.GD.newYearSkinCount < g.GC.newYearSkinCount && (m.GD.newYearSkinCount = 0) : w.ActivityManager.getInstance().checkActivity(w.ActivityType.CHRISTMAS) && (4 == m.GD.personIdx ? m.GD.christmasSkinCount < g.GC.christmasSkinCount && (m.GD.christmasSkinCount++, 
        m.GD.christmasSkinCount == g.GC.christmasSkinCount && (m.GD.christmasDrawTotal = 3)) : m.GD.christmasSkinCount < g.GC.christmasSkinCount && (m.GD.christmasSkinCount = 0)), 
        s.G.playcount++, (GA.isOPPO() || GA.isPlatform(GA.Platform.Vivo) || s.G.isNative()) && g.GC.nativeAdConfig.a && (g.GC.nativeAdConfig.d < 1 && (g.GC.nativeAdConfig.d = 1), 
        g.GC.nativeAdConfig.n <= s.G.playcount && (s.G.playcount - g.GC.nativeAdConfig.n) % g.GC.nativeAdConfig.d == 0 && (_.default.getInstance().nativeFlag = 1)), 
        m.GD.gunIdx < 2e3 && (m.GD.gunIdx < 0 || 1e3 <= m.GD.gunIdx) && (e = s.G.getEggIdx(m.GD.gunIdx), 
        (t = v.default.getInstance().getDataGun(e)) && t.time - Date.now() <= 0 && (0 < v.default.getInstance().checkEggGun(e) ? v.default.getInstance().updateEggGun(e) : m.GD.gunIdx = m.GD.topRank)), 
        m.GD.personIdx < 0 && (28 != (e = s.G.getEggIdx(m.GD.personIdx, 2)) || !(t = v.default.getInstance().getDataPerson(e)).time || t.time < Date.now()) && (0 < v.default.getInstance().checkEggPerson(e) ? v.default.getInstance().updateEggPerson(e) : m.GD.personIdx = m.GD.skins[m.GD.skins.length - 1]), 
        !p.default.getInstance().isHas(1) && 0 < m.GD.hatchLastTime && Math.floor((Date.now() - m.GD.hatchLastTime) / 1e3) >= g.GC.hatchConfig.time && cc.systemEvent.emit("hatch_reward");
    }, e.prototype.onDisable = function() {
        h.default.getInstance().hideGameRecorderShareButton(), u.default.getInstance().quitGame(), 
        cc.systemEvent.off("star", this.callback, this), A.default.getInstance().doShowFSVideo(this.text), 
        t.prototype.onDisable.call(this);
    }, e.prototype.onDestroy = function() {
        t.prototype.onDestroy.call(this), G.default.getInstance().showPnl("start");
    }, e.prototype.onClickVideo = function() {
        var t = this;
        P.default.getInstance().sentLog("点击结算界面视频加星按键"), GA.rewardOperation({
            tag: "star",
            page: "",
            byVideo: !0,
            result: function(e) {
                e.reward && (cc.systemEvent.emit("videoEnd", "star"), cc.isValid(t) && t.callback());
            }
        });
    }, e.prototype.onClickShare = function() {
        var t = this;
        P.default.getInstance().sentLog("点击结算界面分享加星按键"), GA.rewardOperation({
            tag: "star",
            page: "",
            byVideo: !1,
            result: function(e) {
                e.reward && cc.isValid(t) && t.callback();
            }
        });
    }, e.prototype.onClickNext = function() {
        l.default.getInstance().playAudio("按钮2"), this.isEffect || (P.default.getInstance().sentLog("点击结算界面继续按键"), 
        "GameAssistantWeb" in window && window.GameAssistantWeb.showFullScreenVideoAd(), 
        u.default.getInstance().matchType == u.MatchType.引导 ? (m.GD.finishGide(0), P.default.getInstance().sentLog("引导战斗完成")) : 0 < this.piece ? G.default.getInstance().showToast({
            money: this.money,
            diamond: this.diamond,
            piece: this.piece
        }) : G.default.getInstance().showToast({
            money: this.money,
            diamond: this.diamond
        }), this.hidePnl());
    }, e.prototype.onClickBack = function() {
        l.default.getInstance().playAudio("按钮2"), P.default.getInstance().sentLog("点击结算界面返回按键"), 
        this.hidePnl();
    }, e.prototype.onClickRecorder = function() {
        var t = this;
        l.default.getInstance().playAudio("按钮2"), P.default.getInstance().sentLog("TryShareVideo"), 
        h.default.getInstance().isRecorder ? G.default.getInstance().showToast({
            str: "已分享该录屏，请下局再来"
        }) : GA.isPlatform(GA.Platform.ByteDance) ? (this.recorderBtn && (this.recorderBtn.interactable = !1), 
        h.default.getInstance().isRecorder = !0, GA.PA.shareAppMessage({
            channel: "video",
            title: "我就要吃鸡",
            desc: "进入吃鸡的世界",
            imageUrl: "",
            templateId: "3eld33adx4d3bk46j6",
            query: "krq_wjycj=10002",
            extra: {
                videoPath: h.default.getInstance().videoPath,
                videoTopics: [ "我就要吃鸡", "卡日曲游戏" ],
                withVideoId: !0,
                createChallenge: !1
            },
            success: function(e) {
                t.recorderBtn && (t.recorderBtn.interactable = !0), P.default.getInstance().sentLog("ShareVideoSuccess"), 
                m.GD.updateNumber("diamond", 50), G.default.getInstance().showToast({
                    diamond: 50
                }), b.default.getInstance().save(), e.videoId && P.default.getInstance().saveVideoId({
                    aliasId: e.videoId,
                    success: function(e) {
                        console.log("保存视频成功:", e);
                    }
                }), console.log("分享视频成功:", e), t.recorderBtn && (t.recorderBtn.interactable = !1, 
                t.recorderBtn.node.active = !1);
            },
            fail: function(e) {
                P.default.getInstance().sentLog("ShareVideoFailed"), h.default.getInstance().isRecorder = !1, 
                "shareAppMessage:cancel" == e.errMsg || "shareAppMessage:fail video duration is too short" == e.errMsg && G.default.getInstance().showToast({
                    str: "抱歉,录屏时间太短！"
                }), console.log("分享视频失败:", e);
            }
        })) : GA.isPlatform(GA.Platform.Kwaigame) && (this.recorderBtn && (this.recorderBtn.interactable = !1), 
        h.default.getInstance().isRecorder = !0, h.default.getInstance().publishVideo({
            mouldId: "2300000582",
            video: h.default.getInstance().videoId,
            callback: function(e) {
                t.recorderBtn && (t.recorderBtn.interactable = !0), null == e ? (m.GD.updateNumber("diamond", 50), 
                G.default.getInstance().showToast({
                    diamond: 50
                }), b.default.getInstance().save(), t.recorderBtn && (t.recorderBtn.interactable = !1, 
                t.recorderBtn.node.active = !1)) : h.default.getInstance().isRecorder = !1;
            }
        }));
    }, e.prototype.start = function() {
        cc.systemEvent.on("star", this.callback, this), GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) && G.default.getInstance().loadPnl("recorderShow");
    }, e.prototype.callback = function() {
        this.myButton.getComponent(cc.Button).interactable = !1, this.count = 1, m.GD.updateLevel(this.count), 
        b.default.getInstance().save(), this.updateStar(), P.default.getInstance().sentLog("当前星数", m.GD.level);
    }, e.prototype.init = function(e) {
        this.model = e, this.level = m.GD.level, this.updateValue(this.model), m.GD.updateNumber("diamond", this.diamond), 
        m.GD.updateNumber("money", this.money), 0 < this.piece && m.GD.updateNumber("piece", this.piece), 
        s.G.platform == s.Platform.H4399 ? b.default.getInstance().save() : b.default.getInstance().upload({
            json: !0,
            local: !0,
            level: m.GD.level,
            killNum: m.GD.killNum
        }), P.default.getInstance().saveRank({
            data: {
                userid: GA.Info.uid,
                level: m.GD.level
            }
        }), this.myButton.node.active = !0, this.myButton.init("star"), this.showRecorder(), 
        P.default.getInstance().sentLog("当前星数", m.GD.level);
    }, e.prototype.refreshLevel = function(e) {
        this.levelView && this.levelView.refresh(e);
        var t = s.G.getRank(e);
        if (t.r + 1 < g.GC.maxRank ? I.default.getInstance().loadSpriteFrame({
            url: "image/label/" + (t.r + 1),
            sprite: this.labelSprite
        }) : I.default.getInstance().loadSpriteFrame({
            url: "image/label/" + g.GC.maxRank,
            sprite: this.labelSprite
        }), this.rewardView) if (!p.default.getInstance().isHas(0) && g.GC.petRewardConfig.a && g.GC.petRewardConfig.r == t.r + 1) this.rewardView.init({
            type: 1,
            pet: !0
        }); else for (var a = 0; a < g.GC.seasonRewardConfig.length; a++) {
            var n = g.GC.seasonRewardConfig[a];
            if (t.r + 1 == n.r) {
                t.r + 1 > s.G.getRank(m.GD.curLevel).r ? this.rewardView.init({
                    type: 1,
                    personIdx: n.s,
                    diamond: n.d,
                    piece: n.p
                }) : this.rewardView.init({
                    type: 0
                });
                break;
            }
        }
    }, e.prototype.refresh = function() {
        var e;
        this.model && (e = this.model.rank, I.default.getInstance().loadSpriteFrame({
            url: "image/num/rank/" + (e + 1) + "@2x",
            sprite: this.rankSprite
        }), this.refreshLevel(this.level), this.updateStar());
    }, e.prototype.updateValue = function(e) {
        switch (m.GD.killNum += e.kill_count, e.rank) {
          case 0:
            l.default.getInstance().playAudio("游戏成功"), this.rankLabel.string = "第" + (e.rank + 1) + "名   加一星", 
            this.count = 1, this.diamond = 10, this.piece = GA.rand(1, 5);
            break;

          case 1:
            l.default.getInstance().playAudio("游戏失败"), this.rankLabel.string = "第" + (e.rank + 1) + "名   减一星", 
            this.count = -1, this.diamond = 5;
            break;

          case 2:
            l.default.getInstance().playAudio("游戏失败"), this.rankLabel.string = "第" + (e.rank + 1) + "名   减一星", 
            this.count = -1, this.diamond = 4;
            break;

          default:
            l.default.getInstance().playAudio("游戏失败"), this.rankLabel.string = "第" + (e.rank + 1) + "名   减一星", 
            this.count = -1, this.diamond = 3;
        }
        m.GD.level < 0 && (m.GD.level = 0);
        var t = Math.max(g.GC.reward_max - g.GC.reward_reduce * Math.floor(m.GD.topRank / g.GC.reward_interval), g.GC.reward_min);
        0 != this.count && (m.GD.updateLevel(this.count), 0 < this.count ? (s.G.winlast ? (s.G.wincount++, 
        P.default.getInstance().sentLog("连胜", s.G.wincount)) : (s.G.winlast = 1, s.G.wincount = 1, 
        s.G.losecount = 0), m.GD.updateNumber("winNum", 1), this.money = Math.floor(s.G.getPrice(m.GD.topRank) * t) + 200) : (s.G.winlast ? (s.G.winlast = 0, 
        s.G.wincount = 0, s.G.losecount = 1) : (s.G.losecount++, m.GD.tryFailCount = 0, 
        P.default.getInstance().sentLog("连败", s.G.losecount)), this.money = Math.floor(s.G.getPrice(m.GD.topRank) * t / 10) + 20)), 
        p.default.getInstance().check();
    }, e.prototype.updateStar = function() {
        0 < this.count ? this.addStar() : this.count < 0 ? this.subStar() : this.isEffect = !1;
    }, e.prototype.addStar = function() {
        var t, a, n = this;
        0 < this.count && 0 <= this.level ? (this.isEffect = !0, t = s.G.getRank(this.level), 
        this.count--, this.level++, l.default.getInstance().playAudio("得星"), (a = cc.instantiate(this.star)).scale = 30 * a.scale, 
        a.opacity = 0, a.setPosition(cc.v2(this.levelView.stars.children[t.s < this.levelView.stars.childrenCount ? t.s : 0].convertToWorldSpaceAR(cc.Vec2.ZERO)).add(cc.v2(0, 200))), 
        a.parent = cc.director.getScene(), cc.tween(a).parallel(cc.tween().by(.5, {
            position: cc.v2(0, -200)
        }), cc.tween().to(.5, {
            opacity: 255,
            scale: 1.5
        })).call(function() {
            a.destroy();
            var e = s.G.getRank(n.level);
            e.r > t.r ? (t = e, l.default.getInstance().playAudio("晋级段位"), cc.systemEvent.emit("level_warn", !0), 
            I.default.getInstance().loadSpriteFrame({
                url: "image/level/" + e.r,
                sprite: n.sprite2
            }), n.levelView.refreshStar(e.n), n.animation.play("up"), n.animation.on("finished", function() {
                e.r > s.G.getRank(m.GD.curLevel).r && (m.GD.curLevel = n.level, n.doReward(e)), 
                n.addStar();
            }), n.scheduleOnce(function() {
                l.default.getInstance().playAudio("得星"), n.refreshLevel(n.level), n.light.resetSystem();
            }, 2)) : (n.refreshLevel(n.level), n.addStar());
        }).start()) : this.isEffect = !1;
    }, e.prototype.subStar = function() {
        var e, t, a = this;
        this.count < 0 && 0 < this.level ? (this.isEffect = !0, e = s.G.getRank(this.level), 
        this.count++, this.level--, (t = s.G.getRank(this.level)).r < e.r ? (I.default.getInstance().loadSpriteFrame({
            url: "image/level/" + t.r,
            sprite: this.sprite2
        }), this.animation.play("down"), this.animation.on("finished", function() {
            a.refreshLevel(a.level), a.subStar();
        })) : (this.refreshLevel(this.level), this.subStar())) : this.isEffect = !1;
    }, e.prototype.showRecorder = function() {
        GA.isByteDance() ? 1 == g.GC.isRecorder ? h.default.getInstance().videoPath && (this.recorderBtn.node.active = !0) : 2 == g.GC.isRecorder ? 0 < this.count && h.default.getInstance().videoPath && (this.recorderBtn.node.active = !0) : 3 == g.GC.isRecorder && this.count < 0 && h.default.getInstance().videoPath && (this.recorderBtn.node.active = !0) : GA.isPlatform(GA.Platform.Kwaigame) && (isNaN(h.default.getInstance().videoId) || (this.recorderBtn.node.active = !0));
    }, e.prototype.doReward = function(e) {
        this.reward = this.getReward(e), 0 < this.reward.length && (this.reward.forEach(function(e) {
            switch (e.type) {
              case s.RewardType.DIAMOND:
                m.GD.updateNumber("diamond", e.num);
                break;

              case s.RewardType.SKIN:
                m.GD.addSkin(e.idx) && b.default.getInstance().upload({
                    json: !0,
                    local: !0,
                    skin: e.idx
                }), m.GD.personIdx < e.idx && (m.GD.personIdx = e.idx);
                break;

              case s.RewardType.PET:
                p.default.getInstance().isHas(0) || (p.default.getInstance().getRealData(0).has = 1, 
                m.GD.petDataIdx = 0);
                break;

              case s.RewardType.PIECE:
                m.GD.updateNumber("piece", e.num);
                break;

              case s.RewardType.EQUIP:
                y.default.getInstance().addEquip(e.idx), y.default.getInstance().doEquip(e.idx, y.default.getInstance().getConfig(e.idx).type);
            }
        }), b.default.getInstance().save(), G.default.getInstance().loadPopPnl("reward", this.reward[0]));
    }, e.prototype.getReward = function(a) {
        var n = [];
        !p.default.getInstance().isHas(0) && g.GC.petRewardConfig.a && g.GC.petRewardConfig.r == a.r && n.push({
            type: s.RewardType.PET,
            idx: 0
        }), g.GC.equipConfigList.filter(function(e) {
            return 3 == e.options.getType;
        }).forEach(function(e) {
            !y.default.getInstance().getData(e.id).has && e.options.num <= a.r && n.push({
                type: s.RewardType.EQUIP,
                idx: e.id
            });
        });
        for (var e = 0; e < g.GC.seasonRewardConfig.length; e++) !function(e) {
            var t = g.GC.seasonRewardConfig[e];
            a.r == t.r && (isNaN(t.s) || (m.GD.hasSkin(t.s) ? (e = 0 < (e = s.G.personModelList.filter(function(e) {
                return e.id == t.s;
            })).length ? e[0].cost : 200, n.push({
                type: s.RewardType.DIAMOND,
                num: e
            })) : n.push({
                type: s.RewardType.SKIN,
                idx: t.s
            })), isNaN(t.d) || n.push({
                type: s.RewardType.DIAMOND,
                num: t.d
            }), isNaN(t.p) || n.push({
                type: s.RewardType.PIECE,
                num: t.p
            }));
        }(e);
        return n;
    }, a([ C(f.default) ], e.prototype, "myButton", void 0), a([ C(cc.Button) ], e.prototype, "recorderBtn", void 0), 
    a([ C(cc.Label) ], e.prototype, "rankLabel", void 0), a([ C(cc.Sprite) ], e.prototype, "rankSprite", void 0), 
    a([ C(cc.Sprite) ], e.prototype, "labelSprite", void 0), a([ C(c.default) ], e.prototype, "levelView", void 0), 
    a([ C(cc.Sprite) ], e.prototype, "sprite2", void 0), a([ C(cc.Animation) ], e.prototype, "animation", void 0), 
    a([ C(cc.Node) ], e.prototype, "star", void 0), a([ C(cc.ParticleSystem) ], e.prototype, "light", void 0), 
    a([ C(d.default) ], e.prototype, "rewardView", void 0), a([ M ], e);
}(r.default);

n.default = D;